﻿using QueuesClients;
using QueuesClients.WorkStationNotifService;
using QueuesLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Web;

namespace QueuesClients {
    public class WorkStation : QueuesClient<WorkStationNotifServiceClient, WorkStationNotifService.WorkStationNotifService>, IQueuesClient {

        public WorkStation(string id, string ipAddress, string port, string endAddr) :
            base(id, ipAddress, port, endAddr) {
                proxy = new WorkStationNotifServiceClient("WorkStationNotifService", this.Url);
        }

        public override WorkStationNotifServiceClient Proxy {
            get { return proxy; }
        }

        public async Task<string> InitializeAsync(List<Subject> subjects, List<Counter> counters, List<QueueInfo> tickets) {
            try {
                var resp = await Proxy.initializeAsync(subjects, counters, tickets);
                Proxy.Close();
                return resp;
            }
            catch {
                Proxy.Abort();
                throw;
            }
        }

        public string Initialize(List<Subject> subjects, List<Counter> counters, List<QueueInfo> tickets) {
            try {
                var resp = Proxy.initialize(subjects, counters, tickets);
                Proxy.Close();
                return resp;
            }
            catch {
                Proxy.Abort();
                throw;
            }
        }

        public async Task<string> UpdateAllAsync(List<Counter> counters, List<QueueInfo> tickets) {
            try {
                var resp = await Proxy.updateAsync(counters, tickets);
                Proxy.Close();
                return resp;
            }
            catch {
                Proxy.Abort();
                throw;
            }
        }
    }
}